/**
 *  Copyright (C) 2006 zhangbo (freeeob@gmail.com)
 *
 *  This product is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 * 
 *  This product is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 *  author:zhangbo
 *  Email:jsjava@gmail.com
 */
 
function HTMLSelectorUtils(){
	this.jsjava_class="jsorg.eob.component.selector.HTMLSelectorUtils";	
}

/**
 * create select options from a format str
 * @param str a format string : [[text1,value1,label1,select1],[text2,value2,label2,select2],...]
 */
HTMLSelectorUtils.toOptions=function(str){
	var options=new Array();
	var arr=eval(str);
	if(!(arr instanceof Array)){
		return;
	}
	for(var i=0;i<arr.length;i++){
		var info=arr[i];
		if(!(info instanceof Array)){
			return;
		}
		var value=info[0];
		var text=info[1];
		var label=info[2];
		var selected=info[3];
		var option=new Option(text,value);
		options[i]=option;
	}
	return options;
};

/**
 * clone a new options array
 * @param options
 */
HTMLSelectorUtils.cloneOptions=function(options){
	if(!options||!options.length){
		return;
	}
	var arr=new Array();
	for(var i=0;i<options.length;i++){
		var option=options[i];
		var cloneOpt=new Option(option.text,option.value);
		cloneOpt.title=option.title;
		arr[i]=cloneOpt;
	}
	return arr;
};